﻿using System.Text;
using estoque.Model;

namespace estoque.ViewModel
{
    public class ScenarioVM : WorkItemVM
    {
        private string shortInfo;

        internal Scenario Scenario { get; private set; }

        public SortableObservableCollection<TaskVM> Tasks { get; private set; }

        public ScenarioVM(Scenario scenario)
            : base(scenario)
        {
            this.Tasks = new SortableObservableCollection<TaskVM>();
            this.Scenario = scenario;
        }

        public new string ShortInfo
        {
            get
            {
                if (this.IsDirty || string.IsNullOrWhiteSpace(this.shortInfo))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(base.ShortInfo);
                    sb.AppendFormat("hat {0:N0} Tasks zugeordnet", this.Tasks.Count);
                    this.shortInfo = sb.ToString();
                }

                return this.shortInfo;
            }
        }

        public void AddTasks(string text)
        {
            this.Tasks.Add(new TaskVM(text));
        }
    }
}